Hello and welcome to this
demonstration on using Get IMAP Mail Messages
Activity in Studio. In this video, you
will learn to create a workflow that opens
email through IMAP, retrieves first five
unread emails and stores them in a CSV
file using Gmail. Let's begin. Search for a Build DataTable activity in the Activities panel and drag and drop it in
the designer panel. Rename the sequences
email automation and add an annotation to it. Then rename the Build Data
Table activity as dt_GetMails. Click the Data Table button within the Build
Data Table activity. In the pop-up window, create three columns
with headers as Subject with
datatype as String, From with data type as String, and Body with
datatype as String. Click "Okay". Go to the Properties panel of this activity and in
DataTable property, press "Control plus K" to create a new variable
named dt_GetMails. Search for a Get IMAP
Mail Messages activity in the activities
panel and drag and drop it below the
Build Data Table activity and rename it. Go to its Properties
panel and in the MailFolder
property, enter Inbox. In the Port property, enter 993. Click the Server properties
ellipsis icon to open the Expression Editor and
enter "imap.gmail.com". Click "Okay". Click the Email
properties ellipsis icon to open the Expression Editor and enter the email
address in double quotes. Click "Okay". Click
the ellipsis icon of the Password property to open the Expression Editor and enter the password
in double quotes. Ensure that the only Unread Messages property is unchecked. It will fetch all emails
regardless of their read status. In the Top property, enter five, in the Messages property, press "Control plus K" to create a new variable
named New Messages. If you are using your Gmail
username and password, allow your Google account for less secure apps and devices. This can be used by visiting the Security tab under
the Google account page. You can pause this
video here to set your Google account and return
here to continue further. Search for a ForEach activity in the Activities panel and drag and drop it below the Get IMAP Mail Messages activity. Navigate to the
Properties panel of the ForEach activity and click the TypeArgument
property drop-down and select Browse for Types. In the pop-up window, browse for MailMessage type. Select the MailMessage under the System.Net.Mail category. Click "Okay". Now rename
the ForEach activity. Replace the text item from
the first text box with mail. In the adjacent text box, enter the variable newMessages. Search for an Assign activity
in the Activities panel and drag and drop it in
the body section of the ForEach activity, rename it. In the first text box, press "Control plus K" to create a new variable
named Subject. In the adjacent box, enter the expression
mail.Subject. Drag and drop another
Assign activity below the previous Assign
activity and rename it. In the first text box, press Control plus K to create
a new variable named From. In the adjacent box, enter the expression
mail.From.Tostring. Drag and drop another
Assign activity below the previous assign
activity and rename it. In the first text box, press Control plus K to create
a new variable named Body. In the adjacent box, enter the expression
mail.Body.ToString. Now search for an Add
Data Row activity in the Activities
panel and drag and drop it below the third Assign
activity and rename it. Navigate to its Properties
panel and click the ellipsis icon of the ArrayRow property to
open the Expression Editor. Enter the expression
{Subject,From,Body}. Click "Okay". In the
DataTable property, enter the variable dt_GetMails. Search for a Write CSV activity, and drag and drop it below the ForEach activity
and rename it. In the first text box, enter a new CSV file name called "FreshMails.csv" and in
the second text box, enter the DataTable
variable dt_GetMails. Please note that the
CSV file will be created automatically
in the Project folder. Save the project and run it. Now, open the CSV
file FreshMails.csv. All emails are stored in
separate columns under Subject, From, and Body. It is encouraged to
create the workflow as demonstrated and
try this activity. Thank you for watching.